package busstopfinder.db;

import java.util.ArrayList;
import java.util.List;

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.location.Location;
import busstopfinder.ui.Demo;
import busstopfinder.ui.IconMarker;
import busstopfinder.ui.Marker;

import android.bustopfinder.R;


/**
 * This class should be used as a example local data source. It is an example 
 * of how to add data programatically. You can add data either programatically, 
 * SQLite or through any other source.
 * 
 * @author Justin Wetherell <phishman3579@gmail.com>
 */
public class LocalDataSource extends DataSource{
    private List<Marker> cachedMarkers = new ArrayList<Marker>();
    private static Bitmap icon = null;
    
    public LocalDataSource(Resources res) {
        if (res==null) throw new NullPointerException();
        
        createIcon(res);
    }
    
    protected void createIcon(Resources res) {
        if (res==null) throw new NullPointerException();
        icon=BitmapFactory.decodeResource(res, R.drawable.botao_template);
    }
    
    public List<Marker> getMarkers() {
    	
    	// Get local database with stops
    	DatabaseWraper mDb = new DatabaseWraper(Demo.mCtx);
    	
    	// TODO: remove 
    	mDb.seed();
    	
    	// Marker boundaries aprox. 1km;   	
    	Location mFix = ARData.getCurrentLocation();
    	double lat = mFix.getLatitude();
    	double lon = mFix.getLongitude();
    	double deltaLon = 0.015; // 0.015 degrees = 1,3 km
    	double deltaLat = 0.01; // 0.01 degrees = 1,1 km
    	
    	// Get markers from db
    	List<Marker> mDbMarkers = mDb.getMarkers(lat-deltaLat, lat+deltaLat, lon-deltaLon, lon+deltaLon);
    	
    	cachedMarkers = mDbMarkers;
    	
        return cachedMarkers;
    }
}
